package com.longtop.perform.kh.score.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.longtop.framework.base.BaseAction;
import com.longtop.framework.util.BeanUtil;
import com.longtop.framework.util.WebUtil;
import com.longtop.intelliweb.action.IActionContext;
import com.longtop.intelliweb.action.IInitContext;
import com.longtop.intelliweb.view.Dataset;
import com.longtop.perform.kh.score.service.ScoreService;
import com.longtop.perform.khyg.service.ProjectService;

/**
 * 
 * @author 孙景弘
 * 
 */
public class CountScoreAction extends BaseAction {

	private ScoreService service;
	private final String DATASET_PROJECT_SEGMENT = "Dataset_project_segment";

	// 查询条件：
	Map<String, Object> queryMap = new HashMap<String, Object>();

	public CountScoreAction() {
		this.service = this.getBean(ScoreService.BEAN_ID);
	}

	/**
	 * 系统共用：初始化调用
	 */
	public void init(IInitContext context) {
		super.init(context);
	}

	/**
	 * 本页jsp：初始化业务数据(覆写父类方法)
	 */
	public void thisPageInit(IInitContext context) {
		Dataset dataset_project_segment = this.getDataset(context, DATASET_PROJECT_SEGMENT);
		if (!WebUtil.validateDatasetExist(this, dataset_project_segment, DATASET_PROJECT_SEGMENT))
			return;

		String projectId = this.getParameter(context, "projectId");

		// 获取考核方案对应分段
		ProjectService projectService = this.getBean(ProjectService.BEAN_ID);
		List list = projectService.getProjectSegment(projectId);
		BeanUtil.listToDataset(list, dataset_project_segment, false);

	}

	/**
	 * 计算成绩
	 * 
	 * @param context
	 */
	public void countScore(IActionContext context) {

		try {
			String segmentId = this.getParameter(context, "segmentId");
			String msg = service.countScore(segmentId);
			this.hintInfoMessage(msg);
		} catch (Exception e) {
			e.printStackTrace();
			this.hintErrorMessage("计算成绩失败：" + e.getMessage());
		}

	}

	/**
	 * 计算成绩
	 * 
	 * @param context
	 */
	public void issueScore(IActionContext context) {

		try {

			this.hintInfoMessage("待开发。");
		} catch (Exception e) {
			e.printStackTrace();
			this.hintErrorMessage("发布成绩失败："+e.getMessage());
		}

	}
}
